import { BinarySearch } from "../../api/math/BinarySearch";
import { MathUtils } from "../../api/math/MathUtils";
import { CDShopEquipmentLv } from "../excel/CDShopEquipmentLv";


/**
 * 扩展-商城装备等级
 */
export abstract class CEShopEquipmentLv {

    /**
     * 装备等级索引
     */
    private static readonly allUpStageIdList: number[] = [];


    /**初始化 */
    public static init(): void {
        const vs = CDShopEquipmentLv.datas.getValues();
        const list = this.allUpStageIdList;
        for (let i = 0, len = vs.length; i < len; i++) {
            list[i] = vs[i].upStageid;
        }
    }


    /**
     * 根据最大场景id获取等级范围
     * @param maxStageId 
     */
    public static getEquipmentLv(maxStageId: number): number[] {
        const vs = CDShopEquipmentLv.datas.getValues();
        let idx = BinarySearch.getInsertIndex(this.allUpStageIdList, maxStageId);
        if (!BinarySearch.findEqualWhenInsert) {
            idx--;
        }
        idx = MathUtils.clamp(idx, 0, vs.length - 1);
        return vs[idx].equipmentLv;
    }
}